package io.renren.modules.app.controller;

import io.renren.common.utils.R;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.service.ApiCollectService;
import io.renren.modules.sys.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 收藏
 * @author wangyi
 * @mail 794651397@qq.com
 * @createdate 2018/3/19 11:47
 **/
@Api(description = "收藏")
@RestController
@RequestMapping("/app")
public class ApiCollectController {
    @Autowired
    private ApiCollectService apiCollectService;
    @Autowired
    private HttpServletRequest request;
    
    /**
     * 收藏曲谱
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("收藏曲谱*{需要登陆的token}*")
    @Login
     @PostMapping("collectSong")
     public R collectSong(Long songId){
        Long userId=(Long)request.getAttribute("userId");
        SongCollectEntity songCollectEntity=new SongCollectEntity();
        songCollectEntity.setUserId(userId);
        songCollectEntity.setSongId(songId);
        songCollectEntity.setCreateTime(new Date());
        apiCollectService.collectSong(songCollectEntity);
         return R.ok();
     }

    /**
     * 取消收藏曲谱
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("取消收藏曲谱*{需要登陆的token}*")
    @Login
    @PostMapping("cancelCollectSong")
    public R cancelCollectSong(Long songId){
        Long userId=(Long)request.getAttribute("userId");
        SongCollectEntity songCollectEntity=new SongCollectEntity();
        songCollectEntity.setUserId(userId);
        songCollectEntity.setSongId(songId);
        apiCollectService.cancelCollectSong(songCollectEntity);
        return R.ok();
    }

    /**
     * 收藏曲集
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("收藏曲集*{需要登陆的token}*")
    @Login
    @PostMapping("collectSongset")
    public R collectSongset(Long songsetId){
        Long userId=(Long)request.getAttribute("userId");
        SongsetCollectEntity songsetCollectEntity=new SongsetCollectEntity();
        songsetCollectEntity.setUserId(userId);
        songsetCollectEntity.setSongsetId(songsetId);
        songsetCollectEntity.setCreateTime(new Date());
        apiCollectService.collectSongset(songsetCollectEntity);
        return R.ok();
    }

    /**
     * 取消收藏曲集
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("取消收藏曲集*{需要登陆的token}*")
    @Login
    @PostMapping("cancelCollectSongset")
    public R cancelCollectSongset(Long songsetId){
        Long userId=(Long)request.getAttribute("userId");
        SongsetCollectEntity songsetCollectEntity=new SongsetCollectEntity();
        songsetCollectEntity.setUserId(userId);
        songsetCollectEntity.setSongsetId(songsetId);
        apiCollectService.cancelCollectSongset(songsetCollectEntity);
        return R.ok();
    }

    /**
     * 收藏教程
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("收藏教程*{需要登陆的token}*")
    @Login
    @PostMapping("collectTeach")
    public R collectTeach(Long teachId){
        Long userId=(Long)request.getAttribute("userId");
        TeachCollectEntity teachCollectEntity=new TeachCollectEntity();
        teachCollectEntity.setUserId(userId);
        teachCollectEntity.setTeachId(teachId);
        teachCollectEntity.setCreateTime(new Date());
        apiCollectService.collectTeach(teachCollectEntity);
        return R.ok();
    }

    /**
     * 取消收藏教程
     * @author wangyi
     * @createdate 2018/3/19 11:48
     **/
    @ApiOperation("取消收藏教程*{需要登陆的token}*")
    @Login
    @PostMapping("cancelCollectTeach")
    public R cancelCollectTeach(Long teachId){
        Long userId=(Long)request.getAttribute("userId");
        TeachCollectEntity teachCollectEntity=new TeachCollectEntity();
        teachCollectEntity.setUserId(userId);
        teachCollectEntity.setTeachId(teachId);
        apiCollectService.cancelCollectTeach(teachCollectEntity);
        return R.ok();
    }

    /**
     * 查看我收藏的曲谱
     * @author wangyi
     * @createdate 2018/3/19 13:53
     **/
    @ApiOperation("查看我收藏的曲谱*{需要登陆的token}*")
    @Login
     @PostMapping("collectSongList")
     public R collectSongList(){
        Long userId=(Long)request.getAttribute("userId");
         List<SongEntity> list=apiCollectService.collectSongList(userId);
         return R.ok().put("result",list);
     }

     /**
      * 查看我收藏的曲集
      * @author wangyi
      * @createdate 2018/3/19 14:14
      **/
     @ApiOperation("查看我收藏的曲集*{需要登陆的token}*")
     @Login
      @PostMapping("collectSongsetList")
      public R collectSongsetList(){
          Long userId=(Long)request.getAttribute("userId");
          List<SongsetEntity> list=apiCollectService.collectSongsetList(userId);
          return R.ok().put("result",list);
      }

      /**
       * 查看我收藏的教程
       * @author wangyi
       * @createdate 2018/3/19 14:17
       **/
      @ApiOperation("查看我收藏的教程*{需要登陆的token}*")
      @Login
       @PostMapping("collectTeachList")
       public R collectTeachList(){
           Long userId=(Long)request.getAttribute("userId");
           List<TeachEntity> list=apiCollectService.collectTeachList(userId);
           return R.ok().put("result",list);
       }
}
